# demo05_pickle.py
# pickle: 将python类型的数据(list, dict, tuple, set...)直接写入文件
#         从文件中直接读取python类型的数据
# pickle.dump(python类型的数据, 文件操作对象): 写
import pickle
user_info = {"nfx": 123456, "zhangsan": "qwerty"}
fwb = open("/opt/user.data", mode="wb")
pickle.dump(user_info, fwb)  # 将user_info字典写入user.data文件中
fwb.close()
# pickle.load(文件操作对象): 读
frb = open("/opt/user.data", mode="rb")
data = pickle.load(frb)  # 从user.data中直接读取出dict数据
print("data:", data, ", type:", type(data))
print(data["nfx"], data["zhangsan"])
frb.close()
